﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IOrderListInfoService
    {
        IQueryable<OrderListInfo> GetOrderListInfos();
        OrderListInfo GetOrderListInfo(int id);
        void CreateOrderListInfo(OrderListInfo orderListInfo);
        void DeleteOrderListInfo(int id);
        void SaveOrderListInfo();
    }
    
    public class OrderListInfoService : IOrderListInfoService
    {
        private readonly IOrderListInfoRepository orderListInfoRepository;
        private readonly IUnitOfWork unitOfWork;
        public OrderListInfoService(IOrderListInfoRepository orderListInfoRepository, IUnitOfWork unitOfWork)
        {
            this.orderListInfoRepository = orderListInfoRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IOrderListInfoService Members

        public IQueryable<OrderListInfo> GetOrderListInfos()
        {
            var orderListInfos = orderListInfoRepository.GetAll();
            return orderListInfos;
        }

        public OrderListInfo GetOrderListInfo(int id)
        {
            var orderListInfo = orderListInfoRepository.GetById(id);
            return orderListInfo;
        }

        public void CreateOrderListInfo(OrderListInfo orderListInfo)
        {
            orderListInfoRepository.Add(orderListInfo);
            SaveOrderListInfo();
        }

        public void DeleteOrderListInfo(int id)
        {
            var orderListInfo = orderListInfoRepository.GetById(id);
            orderListInfoRepository.Delete(orderListInfo);
            SaveOrderListInfo();
        }

        public void SaveOrderListInfo()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}